package com.bezdelnick.forum.mail;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailException;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;

/**
 * Created by IntelliJ IDEA.
 * User: Bezdelnick
 * Date: 20.07.12
 * Time: 11:57
 * To change this template use File | Settings | File Templates.
 */
public class NotificationMailSender implements MailSender {

    private static final Logger LOGGER = LoggerFactory.getLogger(NotificationMailSender.class);

    @Autowired
    private JavaMailSenderImpl sender;

    @Override
    public void send(SimpleMailMessage simpleMessage) throws MailException {
        try {
            sender.send(simpleMessage);
        } catch (MailException exception) {
            LOGGER.error(exception.getMessage());
        }
    }

    @Override
    public void send(SimpleMailMessage[] simpleMessages) throws MailException {
        for (SimpleMailMessage msg : simpleMessages)
        try {
            sender.send(msg);
        } catch (MailException ex) {
            LOGGER.error(ex.getMessage());
        }
    }

    public JavaMailSenderImpl getSender() {
        return sender;
    }

    public void setSender(JavaMailSenderImpl sender) {
        this.sender = sender;
    }
}
